package cn.tedu.epidemic.webapi.controller;

import cn.tedu.community.commons.pojo.commodity.dto.CommodityDTO;
import cn.tedu.community.commons.pojo.commodity.vo.CommodityListVO;
import cn.tedu.community.commons.pojo.commodity.vo.CommodityStandardByIdVO;
import cn.tedu.community.commons.restful.JsonResult;
import cn.tedu.epidemic.service.CommodityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品管理信息
 */
@Slf4j
@RestController
@Api(tags = "商品管理")
@RequestMapping("/commoditys")
public class CommodityController {
    @Autowired
    private CommodityService commodityService;

    @GetMapping("/list")
    public JsonResult<List<CommodityListVO>> list() {
        List<CommodityListVO> list = commodityService.list();
        return JsonResult.ok(list);
    }

    @GetMapping("/{id:[0-9]+}")
    public JsonResult<CommodityStandardByIdVO> getStandardById(@PathVariable int id) {
        log.debug("开始处理【根据id查询代卖信息详情】的请求，参数：{}", id);
        CommodityStandardByIdVO commodityStandardByIdVO = commodityService.getStandardById(id);
        return JsonResult.ok(commodityStandardByIdVO);
    }
    @PostMapping("/purchase")
    @ApiOperation("用户代买")
    public JsonResult<Void> commodityPurchase(CommodityDTO commodityDTO){
        log.debug("即将开始处理【商品代买】的业务，参数：{}",commodityDTO);
        commodityService.insert(commodityDTO);
        return JsonResult.ok();
    }
}
